define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params, configService) {

	$scope.goback = function(){
		var menu = {};
		menu.url = "modules/content/dataexchange/api/list?father_id="+params.father_id;
		eventBusService.publish("modules.content.load",menu);
	}
	
	//删除
	$scope.delelte = function(){
		var values = [];
		var ids="";
		$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
			var arr=$(this).val().split(',');
			values.push(arr[0]);
			ids = ids+",'"+arr[0]+"'";
		});

		if(values.length < 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
		}else{
			eventBusService.publish("modal.alert", {
				"content": "你是否确认删除这" + values.length + "数据？", "isAutoClose": false, "confirm": function () {
					httpService.post(app.urls.api_deleteApiParam, {"id": ids.replace(',', '')}, function (data) {
						if ("0000" === data.code) {
							$scope.find();
						} else {
							alert(data.msg);
						}
					});
				}, "cancel": function () {
					//用户取消，不做操作
				}
			});
		}
	}
	
	//新增
	$scope.add = function(){
		eventBusService.publish("modal.page","modules/content/dataexchange/api/set/add?fk_api="+params.api_pk);
	}
	
	//修改
	$scope.update = function(){
		var values = [];
    	$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){ 
    		values.push($(this).val());
    	});
    	
    	if(values.length < 1){
    		eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择您要修改的数据。"});
    	}else if(values.length > 1){
    		eventBusService.publish('modal.alert', {"title":"操作提示","content":"不能同时选择多条。"});
    	}else{
    		$scope.form.API_PK = values[0];
    		eventBusService.publish("modal.page","modules/content/dataexchange/api/set/update?FatherControllerName="+$scope.controllerName+"&pk="+values[0]);
    	}
	}
	
	
	$scope.select = function(){
		$scope.find();
	}
	
	
	//接收数据刷新
	eventBusService.subscribe('content.page.reloadin', function(event,data) {
		$scope.select();
	});
	
	$scope.find = function(){
		$scope.form.fk_api = params.api_pk;
		httpService.postpage(app.urls.api_selectApiParam, $scope.form, function(data) {
			if ("0000" === data.code) {
				$scope.dataList = data.data;
			} else {
				alert(data.msg);
			}
		});
	}

	
	var init = function(){
		httpService.post(app.urls.dictionary_selectOne, $scope.form, function(data) {
			if ("0000" === data.code) {
				$scope.dicList = data.data;
				$scope.$apply();
			} else {
				alert(data.msg);
			}
		});
		$scope.form.api_pk = params.api_pk;
		httpService.post(app.urls.api_select, $scope.form, function(data) {
			if ("0000" === data.code) {
				$scope.apiInfo = data.data[0];
				$scope.$apply();
			} else {
				alert(data.msg);
			}
		});
		
	}
	
	init();
	$scope.find();

		//选择数据
		$scope.optData = function (element) {
			if($(element).find("input[name='dataPk']").is(":checked")){
				$(element).find("input[name='dataPk']").prop("checked",false);
				$(element).removeClass("opt_tr");
			}else{
				$(element).find("input[name='dataPk']").prop("checked",true);
				$(element).addClass("opt_tr");
			}
		}
		$scope.checkAll = function(target) {
			$("#" + $scope.controllerName + " input[name='dataPk']").each(function() {
				if ($(this).prop("checked")) {
					$(this).prop('checked', false);
					$(this).parents("tr").removeClass("opt_tr");
				} else {
					$(this).prop('checked', true);
					$(this).parents("tr").addClass("opt_tr");
				}
			})
		}
}}});